#include <bits/stdc++.h>
using namespace std;
const int maxn=200005;
const int MAX=1000005;
int A[maxn],cnt[MAX];
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T;
    cin>>T;
    while(T--){
        memset(cnt,0,sizeof(cnt));
        int n;
        cin>>n;
        for(int i=1;i<=n;i++){
            cin>>A[i];
            cnt[A[i]]++;
        }
        long long ans=0;
        for(int i=1;i<=1000000;i++){
            if(cnt[i])
                ans+=(cnt[i]-1)*i;
        }
        cout<<ans<<endl;
    }
    return 0;
}
